home *** CD-ROM | disk | FTP | other *** search
/ Comic Book Maker: The Smurfs / COMIC.iso / pc / data_w / cba2_40 / 00004_gObj3 balloons.ls < prev    next >
Encoding:
Text File  |  2001-02-22  |  10.5 KB  |  269 lines

  1. property allBalloonInfoList, balloonList, balloonMasterList, defaultBalloonTextSize, balloonMemberList, cBalloonType, cBalloonTypeSize, previousBalloonString, lineHiteDiff, lineStopList, lineMax, activeLine, theSelection, softReturnsList, cBalloonString, activeField, vLocOffset, sndToPlay
  2. global gObj1, gObj2, gObj5, gItemSeparator, gPlatForm
  3.  
  4. on new me
  5.   if not count(the windowList) then
  6.     set allBalloonInfoList to [[9: [[13, -2], [21, 31, -4, [410, 414]]], 7: [[9, -1], [16, 22, -2, [404, 404, 408]]], 5: [[7, 0], [12, 17, 0, [418, 418, 418, 418]]], #offset: point(13, 15)], [9: [[11, -2], [21, 26, -4, [120, 142, 88]]], 7: [[8, -2], [16, 21, 0, [88, 130, 128, 98]]], 5: [[7, -2], [12, 17, -3, [92, 124, 130, 118, 66]]], #offset: point(2, 9)], [9: [[10, 0], [21, 24, -1, [124, 200, 202, 132]]], 7: [[8, 0], [16, 20, 0, [126, 178, 202, 190, 130]]], 5: [[7, 0], [12, 17, 0, [118, 196, 210, 216, 186, 120]]], #offset: point(2, 12)], [9: [[11, -1], [21, 25, 0, [206, 288, 294, 284, 204]]], 7: [[9, -2], [16, 21, -3, [202, 274, 308, 304, 262, 176]]], 5: [[8, -2], [12, 18, -4, [206, 266, 298, 312, 298, 270]]], #offset: point(2, 14)], [9: [[12, 0], [21, 28, 0, [94, 128, 126]]], 7: [[9, -1], [16, 22, -3, [102, 134, 128, 96]]], 5: [[7, -2], [12, 17, -4, [112, 146, 146, 120, 112]]], #offset: point(4, 22)], [9: [[10, 0], [21, 25, 0, [112, 192, 222, 146]]], 7: [[8, -1], [16, 19, -3, [124, 190, 218, 170, 144]]], 5: [[8, -2], [12, 19, -5, [126, 192, 228, 208]]], #offset: point(2, 19)], [9: [[11, 0], [21, 27, 0, [128, 258, 288, 266, 148]]], 7: [[9, -2], [16, 22, -3, [142, 264, 306, 302, 274, 136]]], 5: [[8, -2], [12, 18, -4, [144, 254, 280, 298, 290, 276, 146]]], #offset: point(6, 22)]]
  7.   else
  8.     set balloonMasterList to scanForBalloons(me)
  9.     set balloonList to duplicate(balloonMasterList)
  10.   end if
  11.   set defaultBalloonTextSize to 1
  12.   return me
  13. end
  14.  
  15. on scanForBalloons me
  16.   set allBalloonInfoList to []
  17.   set balloonMemberList to []
  18.   set bList to []
  19.   set end to min(3000, the number of castMembers of castLib 3)
  20.   repeat with i = 2000 to end
  21.     if the name of member i of castLib 3 starts "b." then
  22.       set balloonType to value(char 3 to length(the name of member i of castLib 3) of the name of member i of castLib 3)
  23.       if balloonType and integerp(balloonType) then
  24.         set bID to i + 8 + (balloonType * 10)
  25.         set subList to [bID, bID + 4, bID + 8]
  26.         add(bList, duplicate(subList))
  27.         add(allBalloonInfoList, getData(script i of castLib 3))
  28.         add(balloonMemberList, i)
  29.       end if
  30.     end if
  31.   end repeat
  32.   if not count(bList) then
  33.     alert("No balloons found!")
  34.   end if
  35.   return bList
  36. end
  37.  
  38. on updateBalloonContents me, theSprite
  39.   set balloonID to the balloonID of sprite(theSprite)
  40.   set inputTxt to getAt(getAt(the balloonProps of sprite(theSprite), 4), 2)
  41.   if not gPlatForm then
  42.     set the media of member (balloonID + 2) of castLib 3 to the media of member (balloonID + 2) of castLib 3
  43.   end if
  44.   set the text of member (balloonID + 2) of castLib 3 to inputTxt
  45.   set the textSize of member (balloonID + 2) of castLib 3 to getAt(the balloonProps of sprite(theSprite), 1)
  46.   set the textHeight of member (balloonID + 2) of castLib 3 to getAt(the balloonProps of sprite(theSprite), 2)
  47.   set the scrollTop of member (balloonID + 2) of castLib 3 to getAt(the balloonProps of sprite(theSprite), 3)
  48. end
  49.  
  50. on editText me, fromDialog, theProps, newDefault
  51.   if not fromDialog then
  52.     set theBalloon to getAt(the theSelection of gObj1, 1)
  53.     set theTxt to getAt(the balloonProps of sprite(theBalloon), 4)
  54.     set theSize to getAt(the balloonProps of sprite(theBalloon), 1)
  55.     set dialogNum to 20 + the isBalloon of sprite(theBalloon)
  56.     tell window 1
  57.       displayDialog(dialogNum, theTxt, theSize)
  58.     end tell
  59.     puppetSound(1, "editBalloon")
  60.   else
  61.     set the documentTouched of gObj5 to 1
  62.     set theBalloon to getAt(the theSelection of gObj1, 1)
  63.     set the balloonProps of sprite(theBalloon) to theProps
  64.     updateBalloonContents(me, theBalloon)
  65.     set defaultBalloonTextSize to newDefault
  66.   end if
  67. end
  68.  
  69. on getDefaultBalloonProps me, balloonType
  70.   set propList to duplicate(getAt(getAt(getAt(allBalloonInfoList, balloonType), defaultBalloonTextSize), 1))
  71.   addAt(propList, 1, getPropAt(getAt(allBalloonInfoList, balloonType), defaultBalloonTextSize))
  72.   add(propList, [" ", " "])
  73.   return propList
  74. end
  75.  
  76. on prepareDlog me, num, contents, size
  77.   set cBalloonType to num
  78.   set cBalloonString to getAt(contents, 1)
  79.   set previousBalloonString to cBalloonString
  80.   set cBalloonTypeSize to findPos(getAt(allBalloonInfoList, cBalloonType), size)
  81.   set activeField to cBalloonType + 70
  82.   initBalloon(me, cBalloonTypeSize)
  83.   cutLines(me, 1)
  84. end
  85.  
  86. on initBalloon me, typeSize
  87.   set cBalloonTypeSize to typeSize
  88.   set activeLine to 1
  89.   set softReturnsList to [:]
  90.   set bigFieldPropList to getAt(getAt(getAt(allBalloonInfoList, cBalloonType), typeSize), 2)
  91.   set the textSize of member activeField to getAt(bigFieldPropList, 1)
  92.   if not gPlatForm then
  93.     set the media of member activeField to the media of member activeField
  94.   end if
  95.   set the textSize of member 12 to getAt(bigFieldPropList, 1)
  96.   set the textHeight of member activeField to getAt(bigFieldPropList, 2)
  97.   set lineHiteDiff to the textHeight of member 12 - getAt(bigFieldPropList, 2)
  98.   set selectionOffset to rect(0, lineHiteDiff, 0, lineHiteDiff)
  99.   set vLocOffset to getAt(bigFieldPropList, 3)
  100.   if the frame > 20 then
  101.     beginSprite(sprite(10))
  102.     updateStage()
  103.   end if
  104.   set lineStopList to getAt(bigFieldPropList, 4)
  105.   set lineMax to count(lineStopList)
  106.   set theSelection to [length(cBalloonString)]
  107.   set the text of member 12 to cBalloonString
  108. end
  109.  
  110. on cutLines me, deleteChars
  111.   set end to count(lineStopList)
  112.   set processTxt to EMPTY
  113.   set softReturnsList to [:]
  114.   set tempBalloonString to cBalloonString
  115.   repeat with i = 1 to lineMax + 1
  116.     if tempBalloonString = EMPTY then
  117.       exit repeat
  118.     end if
  119.     put tempBalloonString into field 12
  120.     set rightLoc to getAt(lineStopList, min(i, lineMax))
  121.     set rOffset to locToCharPos(member 12, point(rightLoc, 5)) + 1
  122.     set thisline to char 1 to rOffset of tempBalloonString
  123.     set containsReturn to offset("", thisline)
  124.     if containsReturn then
  125.       if containsReturn = 1 then
  126.         set thisline to RETURN
  127.         delete char 1 of tempBalloonString
  128.       else
  129.         set thisline to char 1 to containsReturn - 1 of thisline & RETURN
  130.         delete char 1 to containsReturn of tempBalloonString
  131.       end if
  132.     else
  133.       if the locH of charPosToLoc(member 12, length(tempBalloonString)) < getAt(lineStopList, min(i, lineMax)) then
  134.         delete char 1 to rOffset of tempBalloonString
  135.       else
  136.         repeat with s = length(thisline) down to 1
  137.           if offset(char s of thisline, " ,-") then
  138.             exit repeat
  139.           end if
  140.         end repeat
  141.         if s > 1 then
  142.           set xOffset to char s of thisline = " "
  143.           set thisline to char 1 to s - xOffset of thisline
  144.           delete char 1 to s of tempBalloonString
  145.           if not xOffset then
  146.             addProp(softReturnsList, length(processTxt), i)
  147.           end if
  148.         else
  149.           delete char 1 to rOffset of tempBalloonString
  150.           addProp(softReturnsList, length(processTxt), i)
  151.         end if
  152.       end if
  153.     end if
  154.     put thisline into line i of processTxt
  155.   end repeat
  156.   if (the number of lines in processTxt > lineMax) and not deleteChars then
  157.     set theSelection to theSelection - 1
  158.     set cBalloonString to previousBalloonString
  159.     set the text of member 12 to cBalloonString
  160.     puppetSound(1, "fieldFull")
  161.   else
  162.     if not voidp(sndToPlay) then
  163.       puppetSound(1, sndToPlay)
  164.     end if
  165.     put line 1 to lineMax of processTxt into field activeField
  166.     set sndToPlay to 0
  167.   end if
  168. end
  169.  
  170. on keyCheck me, key
  171.   set checkNum to charToNum(key)
  172.   case checkNum of
  173.     8:
  174.       if count(theSelection) = 2 then
  175.         delete char max(1, getAt(theSelection, 1)) to getAt(theSelection, 2) of cBalloonString
  176.         deleteAt(theSelection, 2)
  177.         set deleteChars to 1
  178.         set theSelection to theSelection - 1
  179.       else
  180.         if getAt(theSelection, 1) > 0 then
  181.           delete char getAt(theSelection, 1) of cBalloonString
  182.           set theSelection to theSelection - 1
  183.           set deleteChars to 1
  184.         end if
  185.       end if
  186.       set sndToPlay to "deleteKey"
  187.     28:
  188.     29:
  189.     30:
  190.     31:
  191.     127:
  192.       puppetSound(1, "deleteKey")
  193.       delete char getAt(theSelection, 1) + 1 of cBalloonString
  194.       set deleteChars to 1
  195.     3:
  196.       handleDefaultKeyDown(script 1)
  197.       exit
  198.     1, 2, 4:
  199.     otherwise:
  200.       set previousBalloonString to cBalloonString
  201.       if count(theSelection) = 2 then
  202.         set sndToPlay to "key" & random(3)
  203.         if the key = RETURN then
  204.           set sndToPlay to "carriageReturn"
  205.           put numToChar(4) into char max(1, getAt(theSelection, 1)) to getAt(theSelection, 2) of cBalloonString
  206.         else
  207.           put key into char max(1, getAt(theSelection, 1)) to getAt(theSelection, 2) of cBalloonString
  208.         end if
  209.         deleteAt(theSelection, 2)
  210.         set deleteChars to 1
  211.       else
  212.         if the key = RETURN then
  213.           if activeLine = lineMax then
  214.             exit
  215.           end if
  216.           if getAt(theSelection, 1) = 0 then
  217.             put numToChar(4) before char getAt(theSelection, 1) of cBalloonString
  218.           else
  219.             put numToChar(4) after char getAt(theSelection, 1) of cBalloonString
  220.           end if
  221.           set theSelection to theSelection + 1
  222.           set sndToPlay to "carriageReturn"
  223.         else
  224.           if getAt(theSelection, 1) = 0 then
  225.             put key before char getAt(theSelection, 1) of cBalloonString
  226.           else
  227.             put key after char getAt(theSelection, 1) of cBalloonString
  228.           end if
  229.           set sndToPlay to "key" & random(3)
  230.           set theSelection to theSelection + 1
  231.         end if
  232.       end if
  233.   end case
  234.   repeat with i = 1 to 7
  235.     set the locH of sprite (20 + i) to 9000
  236.   end repeat
  237.   updateStage()
  238.   set the text of member 12 to cBalloonString
  239.   cutLines(me, deleteChars)
  240.   updateInsertion()
  241. end
  242.  
  243. on updateInsertion me
  244.   updateInsertion(sprite(10))
  245. end
  246.  
  247. on changeTypeSize me, theSprite, newSize
  248.   clearSelection(sprite(10), 0)
  249.   repeat with i = 1 to 3
  250.     if (i + 30) = theSprite then
  251.       disable(sprite(30 + i))
  252.       next repeat
  253.     end if
  254.     enable(sprite(30 + i))
  255.   end repeat
  256.   updateStage()
  257.   set the text of member activeField to " "
  258.   initBalloon(me, newSize)
  259.   cutLines(me, 1)
  260.   updateInsertion()
  261. end
  262.  
  263. on convert me, input, cutOffChar
  264.   repeat while offset(cutOffChar, input)
  265.     put "@" into char offset(cutOffChar, input) of input
  266.   end repeat
  267.   return input
  268. end
  269.